# Based on Randal Schwartz's code at
# http://www.stonehenge.com/merlyn/UnixReview/col26.html

sub primes {
    my $upper=shift;
    my $i;
    my $vec="";
    my @array;
    $i=2;
    loop: for ($i=2;$i<=$upper;$i++) {
        next loop if vec($vec,$i,1);
        push @array,$i;
        for (my $j=$i**2;$j<=$upper;$j+=$i) {
            vec($vec,$j,1)=1;
        }
    }
    return @array;
}
1;
